package mo.tags.stack;

import java.util.Stack;

public class L739 {

    public int[] dailyTemperatures(int[] temperatures) {
        Stack<Integer> stack = new Stack<>();
        int[] ret = new int[temperatures.length];

        for (int i = 0; i < temperatures.length; i++) {
            while (!stack.isEmpty() && temperatures[stack.peek()] < temperatures[i]) {
                int preIdx = stack.pop();
                ret[preIdx] = i - preIdx;
            }
            stack.push(i);
        }
        return ret;
    }

}